define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'fedition_advertising_info/index' + location.search,
                    add_url: 'fedition_advertising_info/add',
                    edit_url: 'fedition_advertising_info/edit',
                    del_url: 'fedition_advertising_info/del',
                    multi_url: 'fedition_advertising_info/multi',
                    import_url: 'fedition_advertising_info/import',
                    table: 'fedition_advertising_info',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'date_start',
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'accounturl', title: __('店铺名称'),visible: false,addClass: "selectpage", extend: "data-source='feditionaccounturl/index' data-field='name'"},
                        {field: 'accounturl_name', title: __('店铺名称'), operate: false},
                        {field: 'account_id', title: __('账户名称'),visible: false,addClass: "selectpage", extend: "data-source='fedition_advertising/index' data-max-select-limit='5' data-multiple='true' data-field='info'", operate: 'IN'},
                        {field: 'advertising_name', title: __('广告账户'), operate: false},
                        {field: 'date_start', title: __('日期'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime, datetimeFormat:"YYYY-MM-DD"},
                        {field: 'hourly', title: __('Hourly'), operate: 'LIKE'},
                        //{field: 'date_stop', title: __('Date_stop'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'impressions', title: __('Impressions'), operate:'BETWEEN'},
                        {field: 'spend', title: __('Spend'), operate:'BETWEEN'},

                        //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 当表格数据加载完成时
            table.on('load-success.bs.table', function (e, data) {
                //这里可以获取从服务端获取的JSON数据
                $("#zimpressions").text(data.Statistics.zimpressions);
                $("#zspend").text(data.Statistics.zspend);
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});